<?php

        require_once "../../konfigurasi.php";
        
        koneksi_buka();
        
        if(isset($_GET['row_id'])){
                $row_id = $_GET['row_id'];
        }
        
        if(isset($_POST['row_id'])){
                $row_id = $_POST['row_id'];
        }
        
        if(isset($_POST['column'])){
                $column = $_POST['column'];
        }
        
         if(isset($_POST['value'])){
                $value = $_POST['value'];
        }
        
        if(isset($_POST['siswa'])){
                $siswa = $_POST['siswa'];
        }
        
         if(isset($_POST['materi'])){
                $materi = $_POST['materi'];
        }
        $tahun = date("Y");          
        $tgl_daftar = date("Y-m-d");
        $wkt = date("H:i:s");
		if($column=="3"){
			$column_name = "latihan";
		//~ }else if($column=="4"){
			//~ $column_name = "tugas";
		}else if($column=="4"){
			$column_name = "harian";
		}else if($column=="5"){
			$column_name = "uts";
		}else if($column=="6"){
			$column_name = "uas";
		}else{
			$column_name = "akhir";
		}
		
		
		if($row_id=="-"){
			
			$q = "INSERT INTO nilai
					($column_name, siswa, materi, tahun_ajaran) 
					VALUES('$value', '$siswa', '$materi', $tahun)";
			$result = mysql_query($q);
			if($result){
				$id = mysql_insert_id();
					
				echo $id.",".$value;
				
				
			}else{
				echo 'failed query :'.$q ;
			}	
		}else{
			$result = mysql_query("UPDATE nilai SET 
					$column_name = '$value'
					WHERE id=".$row_id);
					
			if($result){
				echo $value." saved";
				
			}else{
					echo 'failed';
			}
		
		}
        
		
		
?>
